using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Identity.Application.Contracts.Common;
using Identity.Application.Permissions.Interfaces;
using Identity.Application.Permissions.Queries;
using MediatR;

namespace Identity.Application.Permissions.QueryHandlers
{
    public class GetAllPermissionQueryHandler : IRequestHandler<GetAllPermissionQuery, Result>
    {
        private readonly IPermissionsReadService _permissionsReadService;
        public GetAllPermissionQueryHandler(IPermissionsReadService permissionsReadService)
        {
            _permissionsReadService = permissionsReadService; 
        }
        public async Task<Result> Handle(GetAllPermissionQuery request, CancellationToken cancellationToken)
        {
            var permissions = await _permissionsReadService.GetListAsync();
            
            return Result.Success(permissions);
        }
    }
}